Ext.define('AmpleHarvest.objects.metrics.sitesRollup.cList',
{
	extend			: 'Ext.grid.Panel',
	alias			: 'widget.ampleharvest-objects-metrics-sitesrollup-clist',
//	anchor			: '100% 100%',
	layout			: 'fit',
	bool_showTbar	: true,
	bool_detailLoad	: false,
	bool_reportLoad : false,
	statics			: {
						M_STR_SITE_SUMMARY_REPRESENTATION 	: 'siteSummaryRepresentation',
						M_STR_FORUM_SUMMARY_REPRESENTATION	: 'forumSummaryRepresentation'
	},
	uses			: [
	    			   'AmpleHarvest.objects.metrics.util.cMetricsUtils'
		],
	columns			: [
	       			   { header : 'Title', dataIndex : 'title', flex : 1, tips: { msg : 'test'} },
	       			   { header : 'Posts', dataIndex : 'postCount', flex : 1 },
	       			   { header : 'Views', dataIndex : 'viewCount', flex : 1 },
	       			   { header : 'Harvested on', dataIndex : 'harvestDate', flex : 1 },
	       			   { header : 'Date of last post', dataIndex : 'lastPostDate', flex : 1 }
	       			   ],
	
	initComponent	: function()
	{
		this.util_metrics = Ext.create('AmpleHarvest.objects.metrics.util.cMetricsUtils');
		
		this.itemsPerPage = 20;
		
		this.store = Ext.create('AmpleHarvest.DATA.Store.cSiteMetricsDirect');

		this.dockedItems = [
		                	   {
		                		   	xtype		: 'pagingtoolbar',
		  							store		: this.getStore(),
		                	   		dock		: 'bottom',
		                	   		displayInfo	: true
		                	   }];
		
		var obj_extraParams = {
				limit		: this.itemsPerPage
		}
		
		if(this.str_directPath)
		{
//			console.log(this.title);
//			console.log('direct path used');
//			console.log(this.str_directPath);
			
			this.getStore().getProxy().url = this.str_directPath;
		}
		
		
		this.callParent();
		
		if(Ext.isArray(this.obj_data))
		{
			this.getStore().set_ExtraParams();
			this.getStore().loadRawData(this.obj_data);
			this.AHcaller.add(this);
		}
		else
		{
			this.getStore().set_ExtraParams(obj_extraParams);
			this.getStore().load();
		}

		if(this.bool_showTbar)
		{
			var obj_params = new Object();
			obj_params = {
					showDefault	: this.showDefaultTbar
				};
			
			if(Ext.isArray(this.tbarOptional))
			{
				obj_params.addBtns = true;
				obj_params.arr_btns	= this.tbarOptional;
			}
			
			this.m_obj_Toolbar = Ext.create('AmpleHarvest.objects.metrics.sitesRollup.cToolBar', obj_params);
			
			this.addDocked(this.m_obj_Toolbar, 'top');
		}
		
		this.on("itemdblclick", this.item_Select, this);
	},
	
	get_path	: function(obj_Record)
	{
		var obj_self = obj_Record.get('self');
		var str_path = false;
		if(!this.str_redirect)
		{
			if(Ext.isObject(obj_Record.get('link-tree')))
			{
				var obj_link = obj_Record.get('link-tree').link
			}
			else
			{
				var obj_link_temp = obj_Record.get('self');
				var obj_link = this.util_metrics.buildLink(obj_link_temp['urn']);
			}
			 
			str_path = this.util_metrics.getLink(['forums','threads'], obj_link)
		}
		
		if(!Ext.isString(str_path)||this.bool_detailLoad)
		{
			str_path = this.util_metrics.buildLink(obj_self['urn']);
			if(!this.bool_reportLoad)
			{
				this.bool_detailLoad = true;
			}	
		}
		//console.log(str_path);
		return str_path;
	},
	
	load_store_from_path	: function(str_path)
	{
		var obj_extraParams = {
				restPath 	: str_path,
				limit		: this.itemsPerPage
			};
		this.getStore().getProxy().url = str_path;
		this.getStore().set_ExtraParams(obj_extraParams);
		this.getStore().load();
	},
	
	load_path	: function(str_path)
	{
		if(this.bool_detailLoad||this.bool_reportLoad)
		{
			if(this.bool_detailLoad)
			{
				m_obj_AmpleHarvest_ViewPort
				.fireEvent(
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_METRICS_SITE_DETAIL,
						str_path
				);
			}
			else
			{
				m_obj_AmpleHarvest_ViewPort
				.fireEvent(
						AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_METRICS_SITE_REPORT,
						str_path
				);
			}
		}
		else
		{
			this.load_store_from_path(str_path);
		}
	},
	
	item_Select	: function(obj_View, obj_Record, obj_HTML, int_Index, obj_Event, obj_Options)
	{
		this.load_path(this.get_path(obj_Record));
	}//this.util_metrics.stripServer()
});